mogx21 Posted September 11, 2008 Share Posted September 11, 2008 Hello, I've got basic knowledge in Java and almost none in PHP, but after researching for the past couple hours, I finally managed to get the following snippet together: <?php function updateDatabase($applicant, $body) { $con = mysql_connect('******','*******','***'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("******"); $counter = 8; $queryAssist; $idProject = 3; $idParentItem = 0; $priorityHolder = 5; $contextHolder = 1; $titleHolder = "Application - $applicant"; $descriptionHolder = "&body"; $durationExpected = 0; $calendarInShow = 0; $privateShow = 0; $idMember = 3; $idAuthor = 1; $idItem = 8; $conditionElement = false; while($conditionElement = false) { if( mysql_query( SELECT * FROM 'frk_item' where 'itemId' = $counter ) { $counter++; } else { $idItem = $counter; $conditionElement = true; } } $query = "INSERT INTO item (itemId, projectId, itemParentId, priority, context, title, description, deadlineDate, expectedDuration, showInCalendar, showPrivate, memberId, authorId) VALUES ('$idItem', '$idProject', '$idParentItem', '$priorityHolder', '$contextHolder', '$titleHolder', '$descriptionHolder', '$dateDeadline', '$durationExpected', '$calendarInShow', '$privateShow', '$idMember', '$idAuthor')"; mysql_query($query) or die('Error, insert query failed'); } ?> The goal is to connect to my mySQL server, and add an entry. The function is called with two parameters and creates an entry with the two parameters, should be somewhat obvious. I don't know why it won't work or what to do, so any advice or alteration would be very helpful. I also had a question, when trying to debug or run my php files, I always just get a page with all the code (minus the whitespace). I was wondering if there were any methods for testing code I should use. I appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/123711-entries-into-mysql/ Share on other sites More sharing options...
Zane Posted September 11, 2008 Share Posted September 11, 2008 if( mysql_query("SELECT * FROM 'frk_item' where 'itemId' = $counter")) Quote Link to comment https://forums.phpfreaks.com/topic/123711-entries-into-mysql/#findComment-638793 Share on other sites More sharing options...
mogx21 Posted September 11, 2008 Author Share Posted September 11, 2008 I fixed my previous issue, but now I am having another. It will only create one database entry and then fail to create anymore. <?php function updateDatabase($applicant, $body) { $con = mysql_connect('10.6.186.64','Wessex','StatelyMatter9'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Wessex"); $queryAssist; $idProject = 3; $idParentItem = 0; $priorityHolder = 5; $contextHolder = 1; $titleHolder = "Application - $applicant"; $descriptionHolder = "&body"; $durationExpected = 0; $calendarInShow = 0; $privateShow = 0; $idMember = 3; $idAuthor = 1; $idItem = 8; $conditionElement = false; while($conditionElement = false) { $counter++; if( mysql_query( "SELECT * FROM 'frk_item' where 'itemId' = $counter" )) { $counter++; } else { $idItem = $counter; $conditionElement = true; } } $query = "INSERT INTO frk_item (itemId, projectId, itemParentId, priority, context, title, description, deadlineDate, expectedDuration, showInCalendar, showPrivate, memberId, authorId) VALUES ('$idItem', '$idProject', '$idParentItem', '$priorityHolder', '$contextHolder', '$titleHolder', '$descriptionHolder', '$dateDeadline', '$durationExpected', '$calendarInShow', '$privateShow', '$idMember', '$idAuthor')"; mysql_query($query) or die('Error, insert query failed'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/123711-entries-into-mysql/#findComment-638899 Share on other sites More sharing options...
JasonLewis Posted September 11, 2008 Share Posted September 11, 2008 while($conditionElement = false) It should be == instead of = You do realize you're incrementing $counter twice. Quote Link to comment https://forums.phpfreaks.com/topic/123711-entries-into-mysql/#findComment-638911 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.