For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > January 2007 > Am I missing something?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Am I missing something?
Alexander

2007-01-27, 9:58 pm

I fixed my code and it shows up fine now. It says it supposedly enters the
data when I input the fields but when I check the MySQL database, the info
isn't there.

Here's the fixed code if you wish to test it:

<html>

<body>

<?php

function add_to_table( $picture, $thumbnail ) {
$picture = mysql_real_escape_string($picture);
$thumbnail = mysql_real_escape_string($thumbnail);

$user = "user";
$pass = "password";
$database = "mydata";

$link = mysql_connect("localhost", $user, $pass);
if(!$link) {
echo 'Error in linking';
}

$db = mysql_select_db($database, $link);

$insert = 'INSERT INTO domains ( picture, thumbnail ) values(
$picture, $thumbnail )';
$indata = mysql_query( $insert, $link );


}

function write_form() {
echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>";

echo "<p>Enter url of large picture: <input type='text'
name='picture' />";

echo "<p>Enter url of thumbnail: <input type='text'
name='thumbnail' />";

echo "<p><input type='submit' value='Add to Database' />";

echo "</form>";
}

if ( !empty( $_REQUEST['picture'] ) && !empty(
$_REQUEST['thumbnail'] ) ) {
$input = add_to_table( $_REQUEST['picture'],
$_REQUEST['thumbnail'] );
if(!input) {
echo 'Error\!';
}
else {
echo 'Data enter successfully\!';
$idreturn = mysql_insert_id($input);
echo 'Image inserted to ID ' . $idreturn;
}
}
else {
write_form();
}

?>

</body>

</html>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com