Jump to content

morrism35

Members
  • Posts

    64
  • Joined

  • Last visited

morrism35's Achievements

Member

Member (2/5)

0

Reputation

2

Community Answers

  1. I want to insert a web link into my pageLink column of my artist_table database so that when someone searches for the artist a link to their webpage comes up, but I keep getting this error message. Error: INSERT INTO artist_table (pageLink) VALUES ('alexander oneal') You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://www.kennethkleiner.com/morris/web250/Artist/alexanderoneal.php>alexander' at line 2 $sql = "INSERT INTO artist_table (pageLink) VALUES ('<a href='http://www.kennethkleiner.com/morris/web250/Artist/alexanderoneal.php'>alexander oneal</a>')";
  2. ok I only changed mysqli_query in my insertData script, i'm assuming it needs to be also in my addColumns script.
  3. I've changed it to mysqli_query, but it didn't make any difference. It is only with this column that it becomes a problem. I'm able to add data with the columns that are already there.
  4. I have imported my database from my localserver into my instructors web server. I want to add a column called pageLink and insert data. I'm getting a "Error: INSERT INTO artist_table (pageLink) VALUES ('jkljk') Unknown column 'pageLink' in 'field list'". As a test I tested my code on other columns and was successfuly able to insert data. My code to add the pageLink column does say successfull but like stated inserting data is saying that pageLink does not exist. Below is my code to add the pageLink column and to insert the pageLink column Adding a column code: $r="ALTER TABLE artist_table ADD COLUMN (pageLink VARCHAR(200))"; $QueryResult=@mysql_query($r, $conn); if($QueryResult===FALSE) echo"Unable to execute the query".mysql_errno($conn).mysql_error($conn); else echo"Success created"; mysqli_close($conn); Inserting data into that column: $sql = "INSERT INTO artist_table (pageLink) VALUES ('jkljk')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close()
  5. thank you mc-gyver so much. I used version b. Version b is very close to what I had in mind, but I was trying to use it like you would make a choice with a typical if/else or switch clause. I understand putting each search term into an array, then it gets a little murky. This was much harder than I thought in my reading or the youtube video that I watched. My next goal is to try and include my song table and find songs based on searching for the song. My easy answer without testing would be to create a join with my song table and artist table, then I just include songs with my query statement in the script.
  6. Ok the trim function did work. Would like to just add functionality to search with last name and groups. I thought it would be as simple as adding an extra like statements underneath the $query.="first_name LIKE '%each' statement but that's not working and the other suggestions are going way over my head. The implode with the OR like "McGuyver" suggested seems to be more understandable but I need to research that a little more.
  7. Found another bug if I add one extra space in my search kjkj kjkj space here it will display the whole table. Getting frustrated this portion of my website it due in 10 days.
  8. Now I'm really confused lol, I'm really trying to keeps this real simple for now. but thanks you guys and girls are great.
  9. Tried it like below but kept getting error messages. Only in my first two months of learning php and mysql so i'm limited so really trying to keep it simple as possible. I'm somewhat familiar how to write this in strictly mysql in a command line or gui but not with php. else if $query.="OR first_name__name LIKE '%$each%'";//ending append from $query statement above if second or later search term else if $query.="OR last_name LIKE '%$each%'";//ending append from $query statement above if second or later search term else if $query.="OR groups LIKE '%$each%'";//ending append from $query statement above if second or later search term
  10. I actually got it to work. My if($numrows>0) was incorrect, now i'm getting results based on the first name column. Now I add functionality so I can search based on the artist last_name, group, and era. Not really sure how to do that, any ideas or hints.
  11. I'm creating a search box for my website but not getting any results. My database is up and working fine and i'm able to select it from my code. I want to be able to pull up different information on a artist by searching his first or last name. <form action='inc_artist_search_box.php' method='get'> <p>Search for your favorite artist, song, or label</p> <input type='text' name='userSearch' value='<?php echo $_GET['userSearch']; ?>' /> <input type='submit' value='Search' /> </form> <hr /> <?php $k=$_GET['userSearch'];//get user search term $terms=explode(" ", $k);//user search term into array $query="Select first_name, last_name, groups, era FROM artist_table WHERE ";//query string appended to querry string after foreach loop $i=0;//counter variable to catch first search term //loop through search term and find terms that are like query request foreach($terms as $each){ $i++; if($i==1) $query.="first_name LIKE '%$each%'";//ending append from $query statement above if first search term else $query.="OR first_name LIKE '%$each%'";//ending append from $query statement above if second or later search term } $servername = '127.0.0.1'; $username = 'root'; $password = 'Conquest1'; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; //select database if(mysqli_select_db($conn,"Artist")) echo "connection successful"; else echo "connection failed"; $query=mysqli_query($conn,$query);//perform the query $numrows=mysqli_num_rows($query);//number of rows in query results found //loop throw rows and extra data if($numrows<0){ while($row=mysqli_fetch_assoc($query)){ $first_name=$row['first_name']; $last_name=$row['last_name']; $group=$row['group']; $era=$row['era']; echo $first_name; echo $last_name; echo $group; echo $era; } } else echo"No search results found for \"<b>$k</b>\"";
  12. Thanks guys that worked. I got all the information from my textbook and it appears my textbook is outdated. My instructor answers his emails maybe 2 wks late so really teaching myself, wasted $250. Ready to transfer from this college.
  13. I have created databases directly in phpmyadmin control panel and in the command line with no problem. The issue is when I create a database with a php script it is not showing up in phpmyadmin control panel or in the command line. My scripts say that the database was created successfully and I was able to verifiy that it is selected by running a mysql select in my script but again it's not showing up in phpmyadmin control panel or command prompt. The code was taken directly from my textbook with the exception of the hosts, user, and password information in the mysql_connect statement. $DBName = "CREATE DATABASE newsletter"; $DBConnect = mysql_connect('127.0.0.1', 'root','Conquest1'); if ($DBConnect === FALSE) echo "<p>Connection error: " . mysql_error() . "</p>\n"; else{ if (mysqli_query($DBConnect, $DBName) === FALSE) echo "<p>Could not create the \"$DBName\" " . "database: " . mysql_error($DBConnect) . "</p>\n"; else echo "<p>Successfully created the " . "\"$DBName\" database.</p>\n"; } if(mysql_select_db($DBName, $DBConnect)===FALSE) echo"works"; else echo"doesn't work";
  14. my classroom text book php mysql programming by Don Gosselin. The reviews say it is one of the worst books for learning php. I've only been learning php about 3 months since the start of fall semester.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.