Jump to content

morrism35

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by morrism35

  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. It worked thanks
  3. ok I only changed mysqli_query in my insertData script, i'm assuming it needs to be also in my addColumns script.
  4. 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.
  5. 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()
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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
  11. 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.
  12. 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>\"";
  13. 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.
  14. 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";
  15. 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.
  16. This site seems to have everything you need to know about php. I've been here before and some of the stuff here looks really advanced. Thank you
  17. Thank you that worked. This command wasn't explained in my manual at least not that i had seen. FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES
  18. looks like its writing the $count variable on another line and the last 2 lines of extra zeros i don't know what thats all about. $count=0; $readin=file('proverb_load.txt', FILE_SKIP_EMPTY_LINES ); $handle = fopen("proverb_load.txt", 'a'); foreach($readin as $r){ $num=0; $count=0; fwrite($handle,$num.$r.$count); } fclose($handle); output: 0jkhkjj 00jkhlkhjljk 00your word for the day 00we wish you a merry christmas 00good tightings to you 00i love football 00 0
  19. input: jkhkjj jkhlkhjljk your word for the day we wish you a merry christmas good tightings to you i love football output: 0jkhkjj 0 0jkhlkhjljk 0 0your word for the day 0 0we wish you a merry christmas 0 0good tightings to you 0 0i love football 0 0 0 Desiredoutput: 0 jkhkjj 0 0 jkhlkhjljk 0 0 your word for the day 0 0 we wish you a merry christmas 0 0 good tightings to you 0 0 i love footballoutput 0 Starting to get really confused been on this assignment all day. I have other assignments were i've wrote text files like this I'm not understanding why this is so diffucult. Please help code: $count=0; $readin=file('proverb_load.txt', FILE_SKIP_EMPTY_LINES ); foreach($readin as $r){ $num=0; $count=0; $handle = fopen("proverb_load.txt", 'a'); fwrite($handle,$num.$r.$count.PHP_EOL); } fclose($handle);
  20. i get it now it is reading an extra line or space. I removed the $num variable and it still wrote a 0. I thought the zero was from the $num variable but apparently its just a space. Now i guess I need to write some time of "if" statement to check for an non-empty line.
  21. foreach($readin as $r){ $num=0; $handle = fopen("proverb_load.txt", 'a'); trim($r); fwrite($handle, $num.$r. PHP_EOL);} fclose($handle); The output is still the same even with trimming the $r variable. I'm not understanding the logic of what you are saying. Why is it writing every line correctly all but the last line where it is adding an extra 0, it looks like it's attempting to iterate one time to many but only outputting the $num variable?
  22. My php file is writing an unwanted 0 at the end of the file. I plan on putting a tab in there to seperate the number and phrase, but that can come later also plan on using the $count variable later. Thank you. Input: jkhkjj jkhlkhjljk your word for the day we wish you a merry christmas good tightings to you i love football output: 0jkhkjj 0jkhlkhjljk 0your word for the day 0we wish you a merry christmas 0good tightings to you 0i love football 0 code: $count=0; $readin=file('proverb_load.txt'); foreach($readin as $r){ $num=0; $handle = fopen("proverb_load.txt", 'a'); fwrite($handle, $num. $r);} fclose($handle);
  23. it was just a typo and my code was correct. My command line isn't displaying it properly for some reason. i do have phpmyadmin and I checked my code in the gui and it was right the whole time. I wasted all this time when I was doing it right in the get go. Same code that I posted above but reading the output in the gui as opposed to the command line(900 just a pasting mistake) 900 Rat 1912 Rat 1924 Rat 1936 Rat 1948 Rat 1960 Rat 1972 Rat 1984 Rat 1996 Rat 2008 Rat 2020 Rat 1901 Ox 1913 Ox 1925 Ox 1937 Ox 1949 Ox 1961 Ox 1973 Ox 1985 Ox 1997 Ox 2009 Ox 2021 Ox
  24. below is my assignment: input, then table code, then output. If I just query the year all the years show correctly, if I query the name then I get missing values for the name. 1900 Rat 1912 Rat 1924 Rat 1936 Rat 1948 Rat 1960 Rat 1972 Rat 1984 Rat 1996 Rat 2008 Rat 2020 Rat 1901 Ox 1913 Ox 1925 Ox 1937 Ox 1949 Ox 1961 Ox 1973 Ox 1985 Ox 1997 Ox 2009 Ox 2021 Ox create table zodiac1( year smallint, name varchar(10) ); load data infile 'C:/xampp/mysql/data/chinese_zodiac/testText.txt' into table zodiac fields terminated by ' '; mysql> select * from zodiac1; +------+----------+ | year | name | +------+----------+ | | Rat | | Rat | | Rat | | Rat | | Rat | | Rat | | Rat | | Rat | | Rat | | Rat | | Rat || Ox || Ox || Ox || Ox || Ox || Ox || Ox || Ox || Ox || Ox || Ox
  25. sorry after i created a new table and loaded those three lines in it worked correctly
×
×
  • 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.